/**
 * Created by CodeTlan.
 * User: Ing. Miguel Salas
 * Date: 3/19/12
 * Time: 2:44 AM
 */
Ext.define('CT.view.contrato.Form', {
    extend:'Ctc.view.Form',
    requires: [
        'CT.view.departamento.Combo',
        'CT.view.categoria.Combo'
    ],
    alias:"widget.formcontrato",
    buildItems:function(){
        return [{
            fieldLabel: 'Contrato',
            enforceMaxLength: true,
            maxLength: 10,
            name: 'contrato'
        },{
            fieldLabel: 'Ficha',
            vtype: 'num',
            enforceMaxLength: true,
            maxLength: 6,
            minLength: 6,
            triggerAction: '',
            name: 'ficha',
            listeners:{
                scope:this,
                validitychange:function(field,isValid,old_value){
                    if(isValid){
                        var comboDep = this.getForm().findField('departamento_k');
                        var storeDep = comboDep.store;
                        comboDep.reset();
                        storeDep.setParams({ "ficha" : field.value });

                        var comboCat = this.getForm().findField('categoria_k');
                        console.log(comboCat);
                        comboCat.reset();
                        comboCat.disable();
                    }
                }
            }
        },{
            xtype: 'datemx',
            fieldLabel: 'Fecha inicio',
            name: 'fecha_inicio'
        },{
            xtype: 'datemx',
            fieldLabel: 'Fecha final',
            name: 'fecha_fin'
        },{
            fieldLabel: 'Dias Contratado',
            xtype: 'numberfield',
            minValue: 0,
            maxValue: 360,
            maxText: 'El valor maximo de dias es de 360',
            name: 'dias',
            vtype: 'num'
        },{
            fieldLabel: 'Departamentos',
            xtype: 'combodepartamentosusuarios',
            name: 'departamento_k',
            listeners:{
                scope:this,
                expand:function(field){
                    field.store.load();
                },
                select:function(combo,record){
                    //console.log(record[0]);
                    var comboCat = this.getForm().findField('categoria_k');
                    var storeCat = comboCat.store;
                    comboCat.enable();
                    comboCat.reset();
                    storeCat.setParams({ "departamento_k" : record[0].data.departamento_k });
                }
            }
        },{
            fieldLabel: 'Categoria',
            xtype: 'combocategorias',
            name: 'categoria_k',
            disabled:true,
            listeners:{
                scope:this,
                expand:function(field){
                    field.store.load();
                }
            }
        }];
    },
    buildButtons:function(){
        return [{
            text: 'Cancelar',
            handler: function() {
                this.up('form').getForm().reset();
            }
        }, {
            text: 'Enviar',
            formBind: true,
            disabled: true,
            action: 'add'
        }];
    }
});